package com.ruoyi.web.controller.business;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusCustomerContact;
import com.ruoyi.business.service.IBusCustomerContactService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户联系人Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@RestController
@RequestMapping("/business/contact")
public class BusCustomerContactController extends BaseController
{
    @Autowired
    private IBusCustomerContactService busCustomerContactService;

    /**
     * 查询客户联系人列表
     */
   // @PreAuthorize("@ss.hasPermi('business:contact:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusCustomerContact busCustomerContact)
    {
        startPage();
        List<BusCustomerContact> list = busCustomerContactService.selectBusCustomerContactList(busCustomerContact);
        return getDataTable(list);
    }

    /**
     * 导出客户联系人列表
     */
   // @PreAuthorize("@ss.hasPermi('business:contact:export')")
    @Log(title = "客户联系人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusCustomerContact busCustomerContact)
    {
        List<BusCustomerContact> list = busCustomerContactService.selectBusCustomerContactList(busCustomerContact);
        ExcelUtil<BusCustomerContact> util = new ExcelUtil<BusCustomerContact>(BusCustomerContact.class);
        return util.exportExcel(list, "客户联系人数据");
    }

    /**
     * 获取客户联系人详细信息
     */
   // @PreAuthorize("@ss.hasPermi('business:contact:query')")
    @GetMapping(value = "/{contactId}")
    public AjaxResult getInfo(@PathVariable("contactId") Long contactId)
    {
        return AjaxResult.success(busCustomerContactService.selectBusCustomerContactByContactId(contactId));
    }

    /**
     * 新增客户联系人
     */
   // @PreAuthorize("@ss.hasPermi('business:contact:add')")
    @Log(title = "客户联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusCustomerContact busCustomerContact)
    {
        busCustomerContact.setCreateBy(getUsername());
        return toAjax(busCustomerContactService.insertBusCustomerContact(busCustomerContact));
    }

    /**
     * 修改客户联系人
     */
   // @PreAuthorize("@ss.hasPermi('business:contact:edit')")
    @Log(title = "客户联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusCustomerContact busCustomerContact)
    {
        busCustomerContact.setUpdateBy(getUsername());
        return toAjax(busCustomerContactService.updateBusCustomerContact(busCustomerContact));
    }

    /**
     * 删除客户联系人
     */
   // @PreAuthorize("@ss.hasPermi('business:contact:remove')")
    @Log(title = "客户联系人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contactIds}")
    public AjaxResult remove(@PathVariable Long[] contactIds)
    {
        return toAjax(busCustomerContactService.deleteBusCustomerContactByContactIds(contactIds));
    }
}
